package com.itxx.keyCase.test4;

import java.io.*;

//序列化Student对象练习题
public class Test4 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("day12\\student.txt"));
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("day12\\student.txt"));

        oos.writeObject(new Student("熊大",13));
        oos.writeObject(new Student("熊二",12));
        oos.writeObject(new Student("光土强",23));
        oos.writeObject(new Student("李老板",30));

        oos.flush();
        Student s1 = (Student) ois.readObject();
        Student s2 = (Student) ois.readObject();
        Student s3 = (Student) ois.readObject();
        Student s4 = (Student) ois.readObject();
       // Student s5 = (Student) ois.readObject();
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println(s4);
       // System.out.println(s5);
            //当读取到最后一个对象时  会抛出异常  解决  将对象条件进一个集合中
        oos.close();
        ois.close();


    }
}
